//
// Created by Chen qin lang on 2018/7/13.
//

#ifndef MYMUSIC_WLVIDEO_H
#define MYMUSIC_WLVIDEO_H

#include "WlCallJava.h"
#include "WlPlaystatus.h"
#include "pthread.h"
#include "WlQueue.h"
#include "WlAudio.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include <libavutil/imgutils.h>

};

#define CODEC_YUV 0
#define CODEC_MEDIACODEC 1


class WlVideo {
public:
    int streamIndex;
    AVCodecContext *avCodecContext = NULL;
    AVCodecParameters *codecpar = NULL;
    int duration;
    WlCallJava *callJava = NULL;
    WlPlaystatus *playstatus = NULL;
    pthread_t play_thread;
    WlQueue *queue = NULL;
    AVRational time_base;
    float clock;
    WlAudio *audio;
    float delay_time;
    double delay_time_base = 0.04;
    pthread_mutex_t codecMutex;
    //AVRational delay_time_base;
    bool codecType = CODEC_YUV;
    AVBSFContext * avbsfContext;
public:
    WlVideo(WlPlaystatus *playstatus, WlCallJava *callJava);

    ~WlVideo();

    void decodeThread();

    void play();

    double getFrameDiffTIme(AVFrame *avFrame,AVPacket* avPacket);

    double getDelayTime(double diff);

    void release();
};


#endif //MYMUSIC_WLVIDEO_H
